import os


class FileUtils:
    """
        文件工具类
    """

    @staticmethod
    def read_file_by_encode(file_path, encode='utf-8'):
        """
            读取文件内容
        """
        with open(file_path, 'r', encoding=encode) as f:
            content = f.read()
        return content

    @staticmethod
    def write_file_by_encode(file_path, content, encode='utf-8'):
        """
            写入文件内容
        """
        with open(file_path, 'w', encoding=encode) as f:
            f.write(content)

    @staticmethod
    def read_file_binary(file_path):
        """
            读取文件内容
        """
        with open(file_path, 'rb') as f:
            content = f.read()
        return content

    @staticmethod
    def write_file_binary(file_path, content):
        """
            写入文件内容
        """
        with open(file_path, 'wb') as f:
            f.write(content)

    @staticmethod
    def copy_file(src_file, dst_file):
        """
            复制文件
        """
        with open(src_file, 'rb') as f:
            content = f.read()
        FileUtils.write_file_binary(dst_file, content)

    @staticmethod
    def delete_file(file_path):
        """
            删除文件
        """
        os.remove(file_path)

    @staticmethod
    def get_file_absolute_path(file_path):
        """
            获取文件绝对路径
        """
        return os.path.abspath(file_path)

    @staticmethod
    def get_file_name(file_path):
        """
            获取文件名
        """
        return os.path.basename(file_path)

    @staticmethod
    def get_file_dir(file_path):
        """
            获取文件目录
        """
        return os.path.dirname(file_path)
